#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>

int main(){
    pid_t cpid=fork();
    if(cpid<0){
        perror("fork failed!\n");
        exit(EXIT_FAILURE);
    }
    else if(cpid==0){
    printf("i am child process\n");
    sleep(5);
    return 0;
    }
    else{
        int status;
       cpid= waitpid(cpid,&status,0);
       if(cpid==-1){
           perror("waitpid failed!\n");
           return -1;
       }
        if(WIFEXITED(status)){
            printf("child's exit code:%d\n",WEXITSTATUS(status));
        }
        else if(WIFSIGNALED(status)){
            printf("child's signal:%d\n",WTERMSIG(status));
            if(WCOREDUMP(status)){
                printf("child's coredump flag:%d\n ",status&0x80);
            }
            }
    }
    return 0;
}
